﻿using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.Items.Weapons.Ranged.Flamethrower
{
    public class FireOfSpace : ModItem
    {
        public override void SetDefaults()
        {
            Item.useStyle = 5;
            Item.autoReuse = true;
            Item.useAnimation = 30;
            Item.useTime = 6;
            Item.width = 50;
            Item.height = 18;
            Item.shoot = 85;
            Item.useAmmo = AmmoID.Gel;
            Item.UseSound = SoundID.Item34;
            Item.damage = 12;
            Item.knockBack = 0.15f;
            Item.shootSpeed = 6.25f;
            Item.noMelee = true;
            Item.value = 26000;
            Item.rare = 1;
            Item.DamageType = DamageClass.Ranged;
        }
        public override bool CanConsumeAmmo(Item ammo, Player player)
        {
            return !(player.itemAnimation < Item.useAnimation - Item.useTime);
        }
        public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
        {
            Vector2 muzzleOffset = Vector2.Normalize(new Vector2(velocity.X, velocity.Y)) * 7;
            if (Collision.CanHit(position, 0, 0, position + muzzleOffset, 0, 0))
            {
                position += muzzleOffset;
            }
            return true;
        }
        public override Vector2? HoldoutOffset()
        {
            return new Vector2(-7, 0);
        }
        public override void AddRecipes()
        {
            CreateRecipe()
           .AddIngredient(ItemID.MeteoriteBar, 22)
           .AddTile(TileID.Anvils)
           .Register();
        }
    }
}
